package com.duowei.diandan.db.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;

import com.duowei.diandan.db.entry.Tcsd;

import java.util.List;

@Dao
public interface TcsdDao {

    @Query("SELECT * FROM tcsd WHERE gq = '1' AND xmbh = :xmbh LIMIT 1")
    Tcsd findMainByXmbh(String xmbh);

    @Query("SELECT * FROM tcsd WHERE gq = '1'")
    List<Tcsd> findMainList();

    @Query("SELECT * FROM tcsd WHERE (gq IS NULL OR gq != '1') AND xmbh = :xmbh GROUP BY tm ORDER BY tm")
    List<Tcsd> findChildByXmbh(String xmbh);

    @Query("SELECT * FROM tcsd WHERE tm = :tm AND xmbh = :xmbh ORDER BY xh")
    List<Tcsd> findChild(String tm, String xmbh);

//    @Query("SELECT tm FROM tcsd WHERE (tm != '' OR tm IS NOT NULL) AND xmbh = :xmbh AND tm NOT LIKE 'A' GROUP BY tm ORDER BY tm")
//    List<String> findChildGroupByTM(String xmbh);

    @Query("SELECT xmbh FROM tcsd WHERE xmbh1 = :xmbh1 GROUP BY xmbh")
    List<String> findByXmbh1(String xmbh1);

    @Query("SELECT xmbh FROM tcsd WHERE xmbh1 IN (SELECT xmbh FROM jyxmsz WHERE xmbh = :xmbh1 AND by21 = '1') GROUP BY xmbh")
    List<String> findByXmbh1By21(String xmbh1);

    @Insert
    void insert(List<Tcsd> list);

    @Query("DELETE FROM tcsd")
    void deleteAll();
}
